﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace StudentVideo.Data.Migrations
{
    /// <inheritdoc />
    public partial class updateDatabase2 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "permission",
                type: "varchar(150)",
                maxLength: 150,
                nullable: false,
                comment: "唯一标识 格式: controller/action:method",
                oldClrType: typeof(string),
                oldType: "varchar(150)",
                oldMaxLength: 150,
                oldComment: "唯一标识")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "role_system_menu_map",
                columns: table => new
                {
                    RoleId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "角色 id")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SystemMenuId = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "系统菜单 id")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_role_system_menu_map", x => new { x.RoleId, x.SystemMenuId });
                    table.ForeignKey(
                        name: "FK_role_system_menu_map_role_RoleId",
                        column: x => x.RoleId,
                        principalTable: "role",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_role_system_menu_map_system_menu_SystemMenuId",
                        column: x => x.SystemMenuId,
                        principalTable: "system_menu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "角色 - 系统菜单 映射")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_role_system_menu_map_RoleId",
                table: "role_system_menu_map",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_role_system_menu_map_SystemMenuId",
                table: "role_system_menu_map",
                column: "SystemMenuId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "role_system_menu_map");

            migrationBuilder.AlterColumn<string>(
                name: "Code",
                table: "permission",
                type: "varchar(150)",
                maxLength: 150,
                nullable: false,
                comment: "唯一标识",
                oldClrType: typeof(string),
                oldType: "varchar(150)",
                oldMaxLength: 150,
                oldComment: "唯一标识 格式: controller/action:method")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");
        }
    }
}
